package org.example.inboundhandlerandoutboundhandler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * @author xuan
 * @create 2023/9/19
 */
public class MyClientInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        //加入一个出站的handler，对数据进行一个编码
        pipeline.addLast("encoderOutbound", new MyLongToByteEncoder());
        pipeline.addLast("decoderInbound", new MyByteToLongDecoder());
        //加入一个自定义的handler，处理业务逻辑
        pipeline.addLast("clientHandlerInbound", new MyClientHandler());
        pipeline.addBefore("clientHandlerInbound", "newOutbound", new TestOutboundHandler());

        pipeline.addAfter("clientHandlerInbound", "newInbound", new TestInboundHandler());
    }
}
